xlv.obj.viewer={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.mvc');
		this.implement('xlv.imp.edc');
	},
	pub:{
		date:'yyyy/MM/dd',
		dateTime:'yyyy/MM/dd HH:mm:ss',
		time:'HH:mm:ss',
		timestamp:'yyyy/MM/dd HH:mm:ss.S'
	},
	create:function(tag){
		var div=document.createElement((tag||'span'));
		div.setAttribute('xlvobject','xlv.obj.viewer');
		return div;			
	},
	properties:{
		dmName:null,
		dmPath:null,
		editable:false,
		dateFormat:false,
		emptyDate:'    /  /  ',
		datePattern:null,
		editor:{objectName:'input'}
	},
	method:{
		construct:function(){
			Element.addClassName(this,'class_viewer');
			if(this.$P.editable) this.tabIndex=0;
			this.styleFor(this);
		},
		initial:function(){
			this.editable(this.$P.editable);
			if(this.$P.dateFormat&&!this.$P.datePattern)this.$P.datePattern=xlv.obj.viewer.pub.date;
		},
		styleFor:function(view){
			view.setAttribute('unselectable','on');
		},
		editable:function(enable){
			this.$P.editable=enable;
			this.edc_enabled(enable);
		},
		/**mvc imp*/
		mvc_valueFromModel:function(dm){
			return this.mvc_isModel(dm) ? dm.getValue(this.$P.dmPath) : null;
		},
		mvc_valueToModel:function(value,dm){
			if(this.mvc_isModel(dm)) dm.setValue(value,this.$P.dmPath);
		},
		mvc_valueFromView:function(){
			var value=xlv.util.getElementValue(this);
			if(this.$P.dateFormat){
				if(this.$P.emptyDate==value) value='';
				else value=new Date().parseDate(value,this.$P.datePattern).formatDate();
			}
			return value;
		},
		mvc_valueToView:function(value){
			if(Object.isElement(value)) value=xlv.util.getElementValue(value);
			if(this.$P.dateFormat) {
				if(value) value=new Date().parseDate(value).formatDate(this.$P.datePattern);
				else value=this.$P.emptyDate;
			}
			xlv.util.setElementValue(this,value);
		},
		///edc
		edc_editable:function(source){
			return (this.$P.editable && this.$P.editor!=null)?this:false;
		},
		edc_policy:function(source){
			return xlv.util.getEditorPolicy(this.$P.editor.objectName);
		},
		edc_installEditor:function(value,policy){
			var p=this.edc_properties;
			var e=this.$P.editor;
			var ignor_dsname=null;
			if(e.properties&&e.properties.dmName!=null&&e.properties.dmName==this.$P.dmName){
				ignor_dsname=e.properties.dmName;
				e.properties.dmName=null;
			}
			var parent=(policy.install=='replace')?p.source:this.getDesktop();
			p.editor=xlv.sys.newInstance(parent,e.objectName,e.properties,e.method);
			if(ignor_dsname!=null)e.properties.dmName=ignor_dsname;
			this.$super('xlv.imp.edc.edc_installEditor',value,policy);
			return p.editor;
		},
		edc_valueFormSource:function(source){
			var dm=this.mvc_getModel();
			return (dm)? this.mvc_valueFromModel(dm):'';
		},
		edc_valueToSource:function(value,source){
			var dm=this.mvc_getModel();
			if(dm)this.mvc_valueToModel(value,dm);
		}
	}
};
